﻿<?php
$shirts = array();

$cart = $_SESSION['cart'];


foreach($cart as $a)
{
	$art = unserialize($a);
	$s = ShirtQuery::create()->findPk($art->shirtId);
	$d = DisponibiliteQuery::create()->filterByShirtId($art->shirtId)->filterByCouleur($art->color)->filterBySexe($art->sex)->filterByTaille($art->size)->findOne();
	$dispo = $stock = ($d->getQuantite()>0)?"En stock":"Rupture";
	array_push($shirts, array("id" => $art->shirtId, "brand" => $s->getMarque(), "description" => $s->getDescription(), "dispo" => $dispo, "price" => $s->getPrix(), "ref" => $art->shirtId, 
		"color" => $art->color, "sex" => $art->sex, "size" => $art->size, "quantity" => $art->quantity, "total" => ($s->getPrix() * $art->quantity)));
}

$smarty->assign("shirts", $shirts);

$conn = unserialize($_SESSION['connexion']);
$q = new ClientQuery();
$client = $q->findOneByEmail($conn->login);

$addr = AdresseQuery::create()->findPk($client->getAdresse());

if($client->getFacturation() == NULL){
	$addrDelivery = $addr;
} else {
	$addrDelivery = AdresseQuery::create()->findPk($client->getFacturation());
}

$title = $addr->getTitre() == 0 ? "Mr" : "Mme";
$name = $addr->getNom();
$firstname = $addr->getPrenom();
$address = $addr->getAdresse();
$postalCode = $addr->getPostal();
$city = $addr->getVille();
$phone = $addr->getTel();
$mail = $conn->login;

$titleDelivery = $addrDelivery->getTitre() == 0 ? "Mr" : "Mme";
$nameDelivery = $addrDelivery->getNom();
$firstnameDelivery = $addrDelivery->getPrenom();
$addressDelivery = $addrDelivery->getAdresse();
$postalCodeDelivery = $addrDelivery->getPostal();
$cityDelivery = $addrDelivery->getVille();
$phoneDelivery = $addrDelivery->getTel();


$smarty->assign("customer", array("title" => $title, "name" => $name, "firstname" => $firstname, "address" => $address, "postalCode" => $postalCode, "city" => $city, "phone" => $phone, "mail" => $mail));
$smarty->assign("customerBis", array("titleDelivery" => $titleDelivery, "nameDelivery" => $nameDelivery, "firstnameDelivery" => $firstnameDelivery, "addressDelivery" => $addressDelivery, "postalCodeDelivery" => $postalCodeDelivery, "cityDelivery" => $cityDelivery, "phoneDelivery" => $phoneDelivery));

		
$smarty->display('cart_validation.tpl');